home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr46
/
acm_rand.zip
/
RAND16.C
next >
Wrap
C/C++ Source or Header
|
1993-01-16
|
767b
|
43 lines
#include "rand16.h"
int _s16r1 = 0;
int _s16r2 = 0;
int _s16r3 = 0;
void srand16(int s1, int s2, int s3)
{
_s16r1 = (s1 % 32362) + 1;
_s16r2 = (s2 % 31726) + 1;
_s16r3 = (s3 % 31656) + 1;
}
int rand16(void)
{
register int z, k;
k = _s16r1 / 206;
_s16r1 = (157 * (_s16r1 - (k * 206))) - (k * 21);
if (_s16r1 < 0)
_s16r1 += 32363;
k = _s16r2 / 217;
_s16r2 = (146 * (_s16r2 - (k * 217))) - (k * 45);
if (_s16r2 < 0)
_s16r2 += 31657;
k = _s16r3 / 222;
_s16r3 = (142 * (_s16r3 - (k * 222))) - (k * 133);
if (_s16r3 < 0)
_s16r3 += 31657;
z = _s16r1 - _s16r2;
if (z > 706)
z -= 32362;
z += _s16r3;
if (z < 1)
z += 32362;
return z;
}
double rand16u(void)
{
return ((double) rand16() * 3.0899e-5);
}